<!DOCTYPE html>
<html>
<head> 
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>爱家-我的爱家</title>
    <link href="/static/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="/static/css/reset.css" rel="stylesheet">
    <link href="/static/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
    <link href="/static/css/ihome/main.css" rel="stylesheet">
    <link href="/static/css/ihome/my.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="top-bar">
            <div class="nav-bar">
                <h3 class="page-title">我的爱家</h3>
                <a class="nav-btn fl" href="/"><span><i class="fa fa-angle-left fa-2x"></i></span></a>
            </div>
        </div>
        <div class="menus-con">
            <ul class="menus-list">
                <li>
                    <div class="menu-title">
                        <h3>个人信息</h3>
                        <a class="fr" href="/profile.html">修改</a>
                    </div>
                    <div class="menu-content">
                        <img id="user-avatar" src="">
                        <div class="menu-text">
                            <h3>用户名：<span id="user-name"></span></h3>
                            <h5>手机号：<span id="user-mobile"></span></h5>
                        </div> 
                    </div>
                </li>
                <li>
                    <div class="menu-title menu-radius">
                        <a href="/orders.html"><h3>我的订单</h3></a>
                    </div>
                </li>
                <li>
                    <div class="menu-title menu-radius">
                        <a href="/auth.html"><h3>实名认证</h3></a>
                    </div>
                </li>
                <li>
                    <div class="menu-title menu-radius">
                        <a href="/myhouse.html"><h3>我的房源</h3></a>
                    </div>
                </li>
                <li>
                    <div class="menu-title menu-radius">
                        <a href="/lorders.html"><h3>客户订单</h3></a>
                    </div>
                </li>
                <li>
                    <div class="menu-title menu-radius" onclick="logout();">
                        <a href="#">退出</a>
                    </div>
                </li>
            </ul>
        </div>
        <div class="footer">
            <p><span><i class="fa fa-copyright"></i></span>爱家租房&nbsp;&nbsp;享受家的温馨</p>
        </div> 
    </div>
    
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="/static/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
    <script src="/static/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <script>
        function getCookie(name) {
                var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
                return r ? r[1] : undefined;
            }

            function logout() {
                $.ajax({
                    url: "/api/v1/logout",
                    type: "delete",
                    headers: {
                        "X-CSRFToken": getCookie("csrf_token")
                    },
                    dataType: "json",
                    success: function (resp) {
                        if ("0" == resp.errno) {
                            location.href = "/index.html";
                        }else{
                            alert(resp.errmsg)
                        }
                    }
                });
            }

            $(document).ready(function () {
                $.get("/api/v1/user", function (resp) {
                    // 用户未登录
                    if ("4001" == resp.errno) {
                        location.href = "/login.html";
                    }
                    // 查询到了用户的信息
                    else if ("0" == resp.errno) {
                        $("#user-name").html(resp.data.name);
                        $("#user-mobile").html(resp.data.mobile);
                        if (resp.data.avatar) {
                            $("#user-avatar").attr("src", resp.data.avatar);
                        }
                    }else if("4000" == resp.errno){
                        //用户未实名
                        location.href = "/auth.html";
                    }
                }, "json");
            })
    </script>
</body>
</html>